#include"../source/server.hpp"

void OnConnected(const PtrConnection &conn)
{
    DBG_LOG("NEW ACCEPT:%p", conn.get());
}

void OnMessage(const PtrConnection &conn, Buffer *buf)
{
    DBG_LOG("%s", buf->ReadPosition());
    // 这里的buf就是Connection连接的输入缓冲区
    buf->MoveReadOffset(buf->ReadAbleSize()); // 模拟一下，已经处理了读到的数据
    const char *data = "hello world";
    conn->Send(data, strlen(data));
}

void OnClosed(const PtrConnection &conn)
{
    DBG_LOG("CLOSE ACCEPT:%p", conn.get());
}
int main()
{
    TcpServer ser(8888);
    ser.SetThreadCount(2);
    //ser.EnableInactiveRelease(10);
    ser.SetConnectedCalllback(OnConnected);
    ser.SetMessageCalllback(OnMessage);
    ser.SetClosedCalllback(OnClosed);

    ser.Start();
    return 0;
}